<template>
	<view class="container">
		<view class="vip_box">
			<view class="vip_change">
				<view class="vip_item" v-for="(item,index) in menuType" :key="index"
					:class="vipCur==index?'vipAc':'vipUn'" @click="changeVip(index)">
					<text class="fcon-f-vip" style="font-size: 32rpx;" v-if="index==1"
						:style="{color:vipCur=='1'?'#FF9700':'#999'}"></text>{{item}}
				</view>
			</view>
		</view>
		<view class="scroll_box p_rlt">
			<empty positions="absolute" :empty="loadedList&&list.length<=0" :zIndexs="99"
				:imgUrl="env.FileUrl+'food/empty/images/empty_ico01.png'" content="暂无数据"></empty>
			<scroll-view class="VerticalNav nav" scroll-y scroll-with-animation>
				<view v-for="(item,index) in list" :key="index" class="sc_item" :id="'left-'+item.parentIds"
					@click="tabLeftMenu($event,index,item,'','','','clicks')" :data-id="item.id">
					<view class="par_item">
						<view :class="index==stabCur?'text-green cur':'uncur'"></view>
						<view class="par_item_item">
							<!-- <image v-if="item.imgurl" :src="item.imgurl" style="width: 48rpx;height: 48rpx;"></image> -->
							<!-- :style="{top:item.nickNames.length==1?(item.topLabels?'8rpx':'-30rpx'):'-20rpx'}" -->
							<view class="badges">
								<uni-badge class="uni-badge-left-margin total" :text="item.num" absolute="rightTop"
									:offset="[item.num&&item.num>=10?5:0, -5]" size="small"></uni-badge>
							</view>
							<view class="menus_tags_box">
								<view class="menus_tags" v-if="item.topLabels&&(item.num<=0|| !isLogin)">
									{{item.topLabels}}</view>
							</view>
							<view class="left_s">
								<image v-if="item.name=='热销'" :src="env.FileUrl+'food/ico/images/dc_left01.png'"
									style="width: 35rpx;height: 35rpx;margin-right: 10rpx;"></image>
								<view>
									<!-- :style="{marginTop:item.nickNames.length==1&&item.topLabels?'10rpx':'0rpx'}" -->
									<view v-for="(itemName,itemindex) in item.nickNames" :key="itemindex">
										{{itemName||''}}
									</view>
									<view v-if="(item.name=='特价'&&(item.num<=0 || !isLogin))" style="color:#FEB74F">天天特价
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="p_rlt vbmbox" :style="`height:${item.height}px`">
						<view class="vbmain" :id="'lefid' + index">
							<view class="view-box-chindred" @tap.stop="tabLeftSubMenu($event,ind,it,'clicks')"
								v-for="(it,ind) in item.children" :key="ind" :data-id="it.nsell_category_id"
								:class="it.nsell_category_id==stabCurs?'childrenActive':''">
								<view style="font-size: 28rpx;">
									<view v-for="(childVname,childInd) in it.childNames" :key="childInd">
										{{childVname}}
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
			<view class="flex">
				<view class="shadowBox"></view>
				<empty positions="absolute" :empty="shopist.length<=0" :zIndexs="99"
					:imgUrl="env.FileUrl+'food/empty/images/empty_ico01.png'" content="暂无数据"></empty>
				<scroll-view class="VerticalMain" scroll-y scroll-with-animation :scroll-into-view="'main-'+mainCur"
					@scroll="VerticalMain">
					<empty positions="absolute" :empty="loadedList&&(list.length>0)&&shopist.length<=0"
						:zIndexs="curPop.value==''?998:9" :imgUrl="env.FileUrl+'food/empty/images/empty_ico06.png'"
						content="暂无菜品"></empty>
					<view v-for="(items,indexs) in shopist" :key="indexs" style="position: relative;"
						:id="'main-'+items.id">
						<view class="vnames" :style="{zIndex:10}" v-if="items.sgoodsList.length>0">
							{{items.vname}}
						</view>
						<view class="cu-bar" v-for="(item,index) in items.sgoodsList" :key="index"
							@click.stop="tapShopItem(item)">
							<image :src="env.FileUrl+'food/images/ico_bao.png'" class="immsb" v-if="item.shopTop=='1'">
							</image>
							<view class="showImgs">
								<tb-image width="100%" height="100%" borderRadius="26rpx"
									:src="imgBaseUrl+item.vmaster_product_image_id">
									<template v-slot:error>
										<image src="../../../static/menuEmpty.png" class="imms" mode="aspectFill">
										</image>
									</template>
								</tb-image>
								<view class="hy text-center" v-if="item.isVip=='1' && !isReplace">
									<text class="fcon-cvip hs_s"></text>
								</view>
								<view class="spcPrice" v-if="item.activityType=='243'">
									<text class="fcon-Vector1 spcPrice_icons"></text>
								</view>
								<view class="sellOut" v-if="item.total_nsell_nums<='0'">已售罄</view>
							</view>
							<view class="shopinfo">
								<view class="shopinfo-shopname">{{item.name}}</view>
								<view class="showinfo-tag">
									<view class="kcal" v-for="(it,ind) in item.tags" :key="ind">{{it}}</view>
								</view>
								<view class="sales_box">
									<view class="sales_box_item"
										v-if="item.warnNums!='0'&&item.nsell_nums<=item.warnNums&&item.total_nsell_nums&&item.total_nsell_nums!='0'&&item.nsell_nums>0">
										仅限{{item.nsell_nums}}份</view>
									<view class="sales_box_item" v-if="item.defaultLabel">
										{{item.defaultLabel}}
									</view>
									<view class="sales_box_item" v-if="item.cupText>0&&vipCur!=0">券后{{item.cupText}}折
									</view>
								</view>
								<!-- <view class="shop-hasDishes" v-if="item.shopType=='1'">含{{item.spec_nums||0}}件菜品</view> -->
								<!-- 	<view class="flex juanhouStyle align-center">
									<text class="juanhouStylefsizi">¥</text><text
										class="juanhoupic">
										{{item.activity ? item.activity_price : (nowSwitch == '1130' ? item.site_sell_price??0 : item.out_sell_price??0)}}
										{{item.activity ? item.activity_price:item.sell_price}}
										</text>
								</view> -->
								<view class="show-price p_rlt">
									<view class="price">
										<!-- 暂 v-if="curSingleMealType=='1175'"-->
										<block>
											<text v-if="curSingleMealType=='1175'||item.showPrice">+</text>
											<text>¥{{ item.showPrice != null ? item.showPrice : (item.activity ? item.activity_price : (shopStore.costPlan == '1130' ? item.site_sell_price ?? 0 : item.out_sell_price ?? 0)) }}</text>
											<!-- 	<text v-if="curSingleMealType=='1175'" class="totalReduce">¥{{item.totalReduce||0}}</text> -->
											<text class="totalReduce">¥{{item.totalReduce||0}}</text>
										</block>

									</view>
									<view v-if="item.specsOnly == '1' || item.shopType=='1'" :class="{
									        priceBtnAv: userVip && item.isVip == '1'&&getAddnums(item),
									        priceBtnAvs: !userVip && item.isVip == '1'||!getAddnums(item),
									        priceBtnAU: item.isVip == '0'&&getAddnums(item)
									      }" @click.stop="openModel(item)" class="speBtn point priceCommon">
										选规格
										<uni-badge class="uni-badge-left-margin total" :text="item.num"
											absolute="rightTop" :offset="[0, -23]" size="normal">
										</uni-badge>
									</view>
									<block v-else>
										<uni-number-box v-if="getAddnums(item)" class="numbx priceCommon"
											v-model="item.num" :min="0" :max="getMaxNum(item)" margin="0 -7rpx"
											:allowInput="true" @changes="changeNum" :sku="item" />
										<view v-else class="prUnis flex flex-direction justify-center align-center"
											@click.stop="stopPrevent">
											<text class="cuIcon-add" style="font-size: 40rpx; color: #666"></text>
										</view>
									</block>
								</view>
								<!-- <view class="evaluate" v-if="item.defaultLabel">{{item.defaultLabel}}</view> -->
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="full_btn fixed padding-top-sm">
			<view class="mbtn" @click.stop="confirm">
				选好了
			</view>
		</view>
		<speciModal ref="popup1" @submit="doSubmit" :isReplace="isReplace"></speciModal>
		<loading></loading>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	import { onShow, onLoad } from "@dcloudio/uni-app";
	import { showLoading, hideLoading, mnavTo, trailingThrottle } from '@/utils/helper';
	import { env } from '@/api/env.js';
	import global from '@/utils/global';
	import { dxGoodsDetial } from '@/api/vmeitime-http/index.js'
	import { useShopStore } from '@/stores/shopStore';
	import { useCartStore } from '@/stores/cartStore';
	import speciModal from '@/components/speciModal/speciModal.vue'
	const popup1 = ref()
	const imgBaseUrl = ref(env.imgBaseUrl)
	const cartStore = useCartStore();
	const shopStore = useShopStore();
	// const menuType = ref(["普餐", "VIP专区"])
	const menuType = ref(["普餐"])
	const vipCur = ref(0)
	const loadedList = ref(false)//是否加载
	const list = ref([])
	const shopist = ref([])
	const load = ref(true)
	const stabCur = ref(0)
	const stabCurs = ref(0)
	const mainCur = ref(0)
	const leftMain = ref(0)
	const verticalNavTop = ref(0)
	const userVip = ref(true)//当前登录用户是否是vip
	const curPop = ref('');//当前打开弹窗
	const curCartList = ref<any>([]);
	const curSingleMealType = ref('');
	const isLogin = ref(false)  //是否登录
	const isReplace = ref(null);//替换商品金额
	const replaceGood = ref('');//替换商品sku
	const replaceMaxNums = ref('');//替换商品最大数
	const pageSource = ref('');
	const changeVip = (index : any) => {
		vipCur.value = index;
		getGoodsDet();
	}
	onLoad((options) => {
		// console.log('clist', cartStore.tcsCarList);
		pageSource.value = options.source||'';
		isReplace.value = options.isReplace || null;//替换商品-nprice 基础价格
		replaceGood.value = options.replaceGood || '';//替换商品-sku
		replaceMaxNums.value = options.replaceMaxNums || 0;//替换商品-最大数
		// if(cartStore.tcsMoreDetail.source=='replace'){

		// }
		// curCartList.value = JSON.parse(JSON.stringify(cartStore.tcsCarList));
		console.log('clist', cartStore.tcsMoreDetail);
		curCartList.value = JSON.parse(JSON.stringify(cartStore.tcsMoreDetail.cart));
		curSingleMealType.value = cartStore.tcsMoreDetail.type || '';

	})
	onShow(() => {
		// tabCur---
		isLogin.value = uni.getStorageSync(global.IS_LOGIN) || false;
		getGoodsDet();
	})
	const parIdGroup = ref<any>({});//parentid分组-已加入购物车商品
	const transQsPrice = (num : any) => {
		if (Number.isInteger(num)) {
			return num; // 如果是整数，直接返回
		} else {
			return num.toFixed(2); // 否则，保留两位小数
		}
	}
	const getGoodsDet = async () => {
		showLoading()
		// cartStore.tcsCarList//单套餐当前将添加购物车商品
		const tcList = cartStore.tcsMoreDetail.skuGroup
		const selectedSkus = Object.values(tcList).filter((item : any) => item.isTaoCan).map((i : any) => i.sku)
		let type = vipCur.value == 0 ? '1128' : '1129';
		const params = {
			vType: type,
			sellMemberId: shopStore.curSellerMemberId,
			serviceType: shopStore.costPlan,
			refSkus: selectedSkus,
			...(isReplace.value && { refPrice: isReplace.value }) // 根据 isReplace 换菜-加菜
		};
		try {
			const res = await dxGoodsDetial(params);
			loadedList.value = true
			if (res.result) {
				list.value = [];
				shopist.value = [];
				load.value = true;
				mainCur.value = 0;
				leftMain.value = 0;
				const cars = getGroups();
				console.log('分组', cars);
				let parIds = {}//parentIds分组
				for (let k = 0; k < res.object.length; k++) {
					let item = res.object[k]
					let childName = item.childList && item.childList.map((childN : any) => {
						return {
							...childN,
							childNames: getNameTags(childN.vname || ''),
							vname: conName(childN.vname || '')
						}
					})

					list.value.push({
						nickNames: item.vname ? getNameTags(item.vname) : [],
						name: conName(item.vname || ''),
						imgurl: item.vlogo ? env.imgBaseUrl + item.vlogo : '',
						id: item.nsell_category_id,
						num: 0,//cars.goodIds[item.goods_id] ? cars.goodIds[item.goods_id].num : 0
						children: childName || [],
						showChild: false,
						parentIds: item.childList && item.childList.length > 0 ? item.childList[0].nsell_category_id : 'f' + k,
						topLabels: item.labels || ''
					})
					if (!item.childList) {
						continue;
					}
					for (let j = 0; j < item.childList.length; j++) {
						let it = item.childList[j];
						let vname = it.nsell_category_id == '-1' ? '热销' : (it.nsell_category_id == '-2' ? '常点' : (it.nsell_category_id == '-3' ? '特价' : conNameReplace(it.vname || '')))
						let sgoodsList = []
						let id = it.nsell_category_id
						let parentid = it.nparent_sell_category_id
						if (!it.goodList) {
							continue;
						}
						for (let m = 0; m < it.goodList.length; m++) {
							let i = it.goodList[m];
							if (cartStore.tcsMoreDetail.skuGroup[i.sku]) {
								console.log('匹配规格', i.sku, i.specList)
								if (!i.specList || i.specList && i.specList.length <= 1) {
									continue;
								}
								// 手动默认规格
								// i.specList = i.specList.filter(istm => istm.sku != i.sku)
								// i.sku = i.specList[0].sku;
								// i.nsell_nums = i.specList[0].nsell_nums;
								// i.old_price = i.specList[0].old_price;
								// i.out_sell_price = i.specList[0].out_sell_price;
								// i.site_sell_price = i.specList[0].site_sell_price;
								// i.sku = i.specList[0].sku;
								// i.specList[0].is_default_buy = '5';
								// console.log('匹配规格1', i.sku, i.specList)
							}

							let litem = {
								...i,
								shopType: i.vtwo_type == '813' ? '1' : '0',
								// isVip: vipCur.value == 0 ? '0' : (i.vipFlag == '6' ? '0' : '1'),
								isVip: i.vipFlag == '6' ? '0' : '1', //VIP标识
								shopTop: i.hotCake,
								specsOnly: (i.specList && i.specList.length > 1) || i.spickLabelFlag ? '1' : '0',
								num: cars.skus[i.sku] ? cars.skus[i.sku].num : 0,
								tags: i.goodsLabels ? i.goodsLabels.split(",") : [],
								// id: i.nsell_category_id,
								totalReduce: i.activity ? (shopStore.costPlan == '1130' ? i.site_sell_price : i.out_sell_price) : i.old_price,
								// nprice:i.activity ? i.activity_price : (shopStore.costPlan == '1130' ? i.site_sell_price ?? 0 : i.out_sell_price ?? 0),
								nprice: shopStore.costPlan == '1130' ? i.site_sell_price ?? 0 : i.out_sell_price ?? 0,
								limited: i.nsell_nums || 0,
								issellOut: i.nsell_nums && i.nsell_nums > 0 ? '1' : '0',
								parentOneId: parentid,
								cupText: getCupText(i)
							}
							//替换商品价格展示
							if (isReplace.value) {
								litem.showPrice = replaceGood.value && isReplace.value < litem.nprice ? (transQsPrice(litem.nprice - isReplace.value)) : 0;
								litem.nsell_nums = replaceMaxNums.value || 0;
								console.log('替换商品--------', litem.nprice, isReplace.value)
							}

							if (litem.num > 0) {
								// parIds分组
								parIds[parentid] ? parIds[parentid].num += litem.num : parIds[parentid] = { id: parentid, num: litem.num, goods_id: litem.goods_id, sku: litem.sku }
							}
							sgoodsList.push(litem)
						}
						sgoodsList.length > 0 && shopist.value.push({
							vname,
							sgoodsList,
							id,
							parentid
						})
					}
				}
				parIdGroup.value = parIds;//parentid分组-已加入购物车商品
				upLeftNums();//同步
				console.log('parIdGroup.value', parIds)
				console.log('list.value', list.value)
				console.log('shopist.value', shopist.value)
				console.log('curCartList.value', curCartList.value)
				hideLoading();
			} else {
				hideLoading()
			}
		} catch (e) {
			console.error(e)
			loadedList.value = true
			hideLoading()
		}
	}
	// 同步左侧-初始化
	const upLeftNums = () => {
		// 同步左侧菜单角标-初始化
		list.value.forEach(item => {
			// console.log('upppp',parIdGroup.value[item.id],parIdGroup.value[item.id].num,item.num)
			parIdGroup.value[item.id] ? item.num = parIdGroup.value[item.id].num : '';
		})

		//同步购物车-初始化
		curCartList.value.forEach(item => {
			for (const key in parIdGroup.value) {
				console.log('bjjjj', key, parIdGroup.value[key])
				if (item.sku && item.sku == parIdGroup.value[key].sku) {
					item.parentOneId = parIdGroup.value[key].id;
					break;
				}
			}
		})
	}
	//分组
	const getGroups = () => {
		let r : any = { goodIds: [], skus: [] };

		if (curCartList.value.length > 0) {
			// let mergedData = {};//goodsId分组
			// curCartList.value.forEach((item : any) => {
			// 	if (mergedData[item.goods_id]) {
			// 		mergedData[item.goods_id].num += item.nums;
			// 	} else {
			// 		mergedData[item.goods_id] = { goods_id: item.goods_id, num: item.nums, sku: item.sku };
			// 	}
			// });
			// // r.goodIds = Object.values(mergedData);
			// r.goodIds = mergedData;

			let spcMergedData = {};//sku分组
			curCartList.value.forEach((item : any) => {
				if (spcMergedData[item.sku]) {
					spcMergedData[item.sku].num += item.nums;
				} else {
					spcMergedData[item.sku] = { num: item.nums, sku: item.sku };
				}
			});
			r.skus = spcMergedData;
			// r.skus = Object.values(spcMergedData);
		}
		return r;
	}
	// 左侧标题换行
	const getNameTags = (namePar : any) => {
		let result = convertToEnglishSymbols(namePar)
		return result ? result.split(",") : []
	}

	const conName = (namePar : any) => {
		let result = convertToEnglishSymbols(namePar)
		return result
	}
	const conNameReplace = (namePar : any) => {
		let newStr : any = '';
		if (namePar) {
			let result = convertToEnglishSymbols(namePar)
			newStr = result.replace(/,/g, '');
		}
		return newStr
	}
	//将所有中文符号转化为英文符号
	const convertToEnglishSymbols = (str : any) => {
		let r : any = '';
		if (str) {
			r = str.replace(/，/g, ',')

		}
		return r

	}
	const getCupText = (i : any) => {
		let result = i.activity ? ((i.activity_price ?? 0) / (i.old_price ?? 1) * 100).toFixed(0) : (shopStore.costPlan == '1130' ? ((i.site_sell_price ?? 0) / (i.old_price ?? 1) * 100).toFixed(0) : ((i.out_sell_price ?? 0) / (i.old_price ?? 1) * 100).toFixed(0))
		if (result.length >= 100) {
			return 0
		}
		const numberStr = result.toString();
		const lastDigit = numberStr[numberStr.length - 1];
		if (lastDigit === '0') {
			return numberStr[0];
		} else {
			return numberStr;
		}
	}

	// 点击左侧菜单
	const tabSelecLeft = (e : any, index : any, item : any = {}, shopId : any, isHid : any, source : any = '', shockSource : any = '') => {
		console.log()

		// stabCurs.value
		if (shockSource == 'clicks') {
			uni.vibrateShort();
		}
		stabCur.value = index;
		if (
			(item.children?.length > 0 && (Number(item.children[0].nsell_category_id) < 0 || Number(shopId) < 0)) ||
			(item.children?.length == 1 && item.name == item.children[0].vname)
		) {
			let e = {
				currentTarget: {
					dataset: {
						id: item.children[0].nsell_category_id
					}
				}
			};
			changescIndex(e, "", "");
		}

		if (item.children && item.children.length == 0) {
			let e = {
				currentTarget: {
					dataset: {
						id: item.id
					}
				}
			};
			changescIndex(e, "", "");
		}

		list.value[index].showChild = !list.value[index].showChild

		if (list.value[index].showChild) {
			const query = uni.createSelectorQuery();
			query.select(('#lefid' + index)).boundingClientRect(); // 选择类名为my-element的元素
			query.exec((res) => {
				if (res[0]) {
					// item && item.children && item.children.length > 0 && (Number(item.children[0].nsell_category_id) < 0)
					if ((item && item.children && item.children.length > 0 && (Number(item.children[0].nsell_category_id) < 0) || (item && item.children && item.children.length == 1 && item.name == item.children[0].vname))) {
						list.value[index].height = 0
					} else if (Number(shopId) < 0) {
						list.value[index].height = 0
					} else {
						list.value[index].height = res[0].height
					}
				}
			});
		} else {
			// lefAnimationChange(0)
			list.value[index].height = 0;
		}
		for (let i in list.value) {

			if (i != index) {
				list.value[i].showChild = false
				list.value[i].height = 0
			}
		}

	}
	const changescIndex = (e : any, index : any, item : any, shockSource : any = '') => {
		shockSource == 'clicks' && uni.vibrateShort();
		stabCurs.value = e.currentTarget.dataset.id
		mainCur.value = e.currentTarget.dataset.id;
		verticalNavTop.value = (e.currentTarget.dataset.id - 1) * 50
	}
	const tabLeftMenu = trailingThrottle(tabSelecLeft, 80);
	const tabLeftSubMenu = trailingThrottle(changescIndex, 80);
	// 滚动
	const VerticalMain = (e : any) => {
		mainCur.value = 0
		if (e.detail.scrollTop == 0) {
			leftMain.value = list.value[0].parentIds
		}
		let tabHeight = 0;
		if (load.value) {
			for (let i = 0; i < shopist.value.length; i++) {
				let view = uni.createSelectorQuery().select("#main-" + shopist.value[i].id);
				view.fields({
					size: true
				}, (data : any) => {
					shopist.value[i].top = tabHeight;
					tabHeight = tabHeight + data.height;
					shopist.value[i].bottom = tabHeight;
				}).exec();
			}
			load.value = false
		}
		let scrollTop = e.detail.scrollTop + 10;
		for (let i = 0; i < shopist.value.length; i++) {
			if (scrollTop > shopist.value[i].top && scrollTop < shopist.value[i].bottom) {
				verticalNavTop.value = (shopist.value[i].id - 1) * 50
				stabCurs.value = shopist.value[i].id
				leftMain.value = shopist.value[i].id
				const result = findParentIndexById(list.value, shopist.value[i].id)
				if (result !== null) {
					if (typeof list.value[result].height === 'undefined' || list.value[result].height == 0) {
						if (!(list.value[result].children && list.value[result].children.length == 1 && list.value[result].name == list.value[result].children[0].vname)) {
							tabSelecLeft("", result, "", shopist.value[i].id, 'hids')
						} else {
							tabSelecLeft("", result, "", "-" + shopist.value[i].id, 'hids')
						}

					}
				}
				return false
			}
		}
	}
	const findParentIndexById = (items : any, id : any) => {
		let result = null;
		items.forEach((parent : any, parentIndex : any) => {
			parent.children.forEach((child : any) => {
				if (child.nsell_category_id == id) {
					result = parentIndex;
				}
			});
		});
		return result;
	}

	const tapShopItem = (item : any) => {
		// mnavTo('/pages/order/goodsDetial/goodsDetial?shopType=' + item.shopType + "&goodsId=" + item.goods_id)
	}
	const getAddnums = (item : any) => {
		if (!item.specList) {
			return false
		}
		let sellOuts = item.specList && item.specList.every((it : any) => Number(it.num ?? 0) >= Number(it.nsell_nums))
		if (userVip) {
			if (cartStore.curOrderType.type !== '') {
				return true;
			} else if (!sellOuts && !shopStore.hasShut && cartStore.curOrderType.type == '' && shopStore.shutStates == 'opens') {
				return true
			}
		} else {
			if (cartStore.curOrderType.type !== '') {
				if (vipCur.value == 0) {
					return true;
				} else if (vipCur.value == 1) {
					return false;
				}
			} else if (!sellOuts && !shopStore.hasShut && cartStore.curOrderType.type == '' && shopStore.shutStates == 'opens' && vipCur.value == 0) {
				return true;
			}
		}
		return false
	}
	const getMaxNum = (item : any) => {
		// cartStore.curOrderType.type==''?item.nsell_nums:9999
		if (cartStore.curOrderType.type == 'SUBSCRIBE') {
			if (shopStore.hasShut && shopStore.shutStates != 'opens') {
				return 0
			} else {
				return item.nsell_nums
			}
		} else {
			return item.nsell_nums
		}
	}
	const openModel = (item : any) => {
		console.log('opmd', item)
		if (item.statu == '0' || vipCur.value == 1 && !userVip.value) {
			return
		}
		if (!userVip.value && item.isVip == '1') {
			return
		}
		if (item.specList && item.specList.length > 1) {
			let cindex = item.specList.findIndex(citem => cartStore.tcsMoreDetail.skuGroup[citem.sku]);
			cindex >= 0 ? item.specList.splice(cindex, 1) : '';
		}

		if (item.shopType == '0') {
			// showPop('popup1')
			popup1.value.open(item)//规格选择弹窗
		} else {
			// mnavTo('/pages/order/goodsDetial/goodsDetial')
		}
	}
	// 规格弹窗添加商品
	const doSubmit = (r : any) => {
		console.log('规格0',curCartList.value)
		r.goodsItem.num += 1;
		let index = curCartList.value.findIndex(item=>item.sku==r.result.sku);
		r.result.cnum = index>=0?curCartList.value[index].nums + 1:1;
		console.log('规格+',index,r)
		console.log('规格+111',curCartList.value[index])
		uni.vibrateShort();
		addCar(r.e, r.result, 'modal')
		hidePop('popup1')
		// cartStore.setTsCarList()
	}

	const confirm = (r : any) => {
		console.log('confirm', curCartList.value)
		uni.vibrateShort();
		cartStore.setTsCarList(curCartList.value)
		uni.navigateBack()
	}
	const showPop = (source : string) => {
		curPop.value = source;
		switch (source) {
			case 'popup1':
				popup1.value?.open()//规格选择弹窗
				break;
			default:
				break;
		}
	}
	const hidePop = (source : string) => {
		switch (source) {
			case 'popup1':
				popup1.value?.close()//规格选择弹窗
				break;
			default:
				break;
		}
	}

	// +-数量按钮
	const changeNum = (e : any) => {
		console.log('changeNum', e)
		const csku = e.sku.sku || '', citem = e.sku, cnum = e.nums;
		let param = {
			name: citem.name || '',
			img: citem.vimage || citem.vmaster_product_image_id || '',
			nums: cnum,
			goods_id: citem.goods_id,
			sku: citem.sku,
			isVip: citem.isVip,
			labelIds: citem.labelIds || [],
			parentOneId: citem.parentOneId || '',
			// nprice: citem.activity ? citem.activity_price : (shopStore.costPlan == '1130' ? citem.site_sell_price ?? 0 : citem.out_sell_price ?? 0),
			nprice: shopStore.costPlan == '1130' ? citem.site_sell_price ?? 0 : citem.out_sell_price ?? 0, //vip取销售价格
			replaceSku: replaceGood.value ? replaceGood.value : '',//替换的原商品sku
			replaceGroupId: replaceGood.value ? cartStore.tcsMoreDetail.changeGoupId : '',//替换的套餐组
			addGroupId:pageSource.value=='manyMeal'?cartStore.tcsMoreDetail.groupId:''
			// isTaoCan:isReplace.value?true:false
		}
		changeCar(csku, cnum, param);
	}

	// 添加商品-规格弹窗添加商品
	const addCar = async (e : any, item : any, source : any = '') => {
		console.log('添加商品addcar', e, item, item.num)
		// source!='modal'
		let citem = {
			name: item.name || '',
			img: item.vimage || item.vmaster_product_image_id || '',
			nums: source == 'modal' ? item.cnum: item.num,//item.cnum
			sku: item.sku,
			isVip: item.isVip,
			goods_id: item.goods_id,
			labelIds: item.labelIds || [],
			parentOneId: item.parentOneId || '',
			// nprice: item.activity ? item.activity_price : (shopStore.costPlan == '1130' ? item.site_sell_price ?? 0 : item.out_sell_price ?? 0),
			nprice: shopStore.costPlan == '1130' ? item.site_sell_price ?? 0 : item.out_sell_price ?? 0, //vip取销售价格
			replaceSku: replaceGood.value ? replaceGood.value : '',//替换的原商品sku
			replaceGroupId: replaceGood.value ? cartStore.tcsMoreDetail.changeGoupId : '',//替换的套餐组
			addGroupId:pageSource.value=='manyMeal'?cartStore.tcsMoreDetail.groupId:''//多套更多商品手动加入组
			// isTaoCan:isReplace.value?true:false
		}
		changeCar(citem.sku, citem.nums, citem)
	}
	const changedPreItem = ref<any>({});//暂存上次修改的商品信息 
	// 同步购物车商品/同步左侧列表角标
	const changeCar = (sku : any = '', num : any = 0, item : any) => {
		console.log('pre0', changedPreItem.value)
		if (changedPreItem.value.sku && replaceGood.value) {
			const sindex = shopist.value.findIndex(sitem => sitem.parentid == changedPreItem.value.parentOneId)
			console.log('pre1', sindex, shopist.value[sindex])
			if (sindex >= 0) {
				const gindex = shopist.value[sindex].sgoodsList.findIndex(gitem => gitem.sku == changedPreItem.value.sku)
				console.log('pre2', gindex, shopist.value[sindex].sgoodsList[gindex])
				gindex >= 0 ? shopist.value[sindex].sgoodsList[gindex].num = 0 : '';
				const uindex = curCartList.value.findIndex(uitem => changedPreItem.value.sku == uitem.sku);
				console.log('pre3', uindex, curCartList.value[uindex])
				uindex >= 0 ? curCartList.value.splice(uindex, 1) : '';
				// const lindex = list.value.findIndex(litem => litem.id && litem.id == item.parentOneId);
			}

		}
		changedPreItem.value = item;
		const index = curCartList.value.findIndex(ritem => sku && sku == ritem.sku);
		index >= 0 ? (num <= 0 ? curCartList.value.splice(index, 1) : curCartList.value[index].nums = num) : curCartList.value.push(item);
		console.log('同步购', curCartList.value, index)
		// 同步左侧
		let ltnums = 0;
		curCartList.value.forEach(citem => {
			ltnums += citem.sku == item.sku ? item.nums : citem.nums
			// if (citem.parentOneId == item.parentOneId) {
			// 	ltnums += citem.sku == item.sku ? item.nums : citem.nums
			// }
		})
		const lindex = list.value.findIndex(litem => litem.id && litem.id == item.parentOneId);
		lindex >= 0 ? list.value[lindex].num = ltnums : '';
	}
	// const delCar = async (e : any, item : any) => {}
	const stopPrevent = async () => { }
</script>

<style lang="scss" scoped>
	.container {
		.vip_box {
			width: 100%;
			height: 96rpx;
			// border: 1px solid red;
			// margin-top: 4rpx;
			display: flex;
			justify-content: space-between;
			background-color: #fff;
			align-items: center;
			padding: 0rpx 20rpx 0rpx 20rpx;

			.vip_change {
				height: 100%;
				width: 520rpx;
				display: flex;
				align-items: center;

				.vip_item {
					margin-left: 35rpx;
				}

				.vipAc {
					color: #333;
					font-family: "Microsoft YaHei UI";
					font-size: 32rpx;
					font-weight: 700;
					letter-spacing: 0.48px;
				}

				.vipUn {
					color: #999;
					font-family: "Microsoft YaHei UI";
					font-size: 28rpx;
					font-weight: 400;
					letter-spacing: 0.48px;
				}
			}

			.tas_type {
				display: flex;
				color: #333;
				font-size: 28rpx;
				margin-top: -5rpx;

				.icss_rig {
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
					background: rgba(83, 168, 127, 0.10);
					padding-top: 5rpx;
				}
			}
		}

		.scroll_box {
			width: 100%;
			height: calc(100vh - 248rpx); //96 + 2 +150 
			margin-top: 2rpx;
			display: flex;
		}

		.VerticalNav {
			height: 100%;
		}

		.VerticalNav.nav {
			width: 170rpx;
			white-space: initial;
			position: relative;
		}

		.VerticalNav.nav .cu-item {
			width: 100%;
			text-align: center;
			margin: 0;
			border: none;
			min-height: 90rpx;
			position: relative;
			height: auto;
			padding: 0;

			.view-box-chindred {
				color: #666;
				text-align: center;
				font-family: "Microsoft YaHei UI";
				font-size: 28rpx;
				font-style: normal;
				font-weight: 400;
				min-height: 90rpx;
				height: auto;
				background-color: #F5F7F6;
				// border: 1px solid #000;
				margin-top: 20rpx;
			}
		}

		.VerticalNav.nav .cu-item:nth-child(n+2) {
			margin-top: 20rpx;
		}

		.VerticalNav.nav .cu-item.cur {
			background-color: #fff;
			color: #648C6A;
			text-align: center;
			font-family: "Microsoft YaHei UI";
			font-size: 25rpx;
			font-style: normal;
			font-weight: 700;
		}

		.VerticalNav.nav .cu-item.uncur {
			color: #666;
			text-align: center;
			font-family: "Microsoft YaHei UI";
			font-size: 25rpx;
			font-style: normal;
			font-weight: 400;
		}

		.VerticalNav.nav .cu-item.cur::after {
			content: "";
			width: 14upx;
			height: 90rpx;
			position: absolute;
			background-color: currentColor;
			top: 0;
			left: 0rpx;
			bottom: 0;
		}

		.vbmbox {
			transition: height 0.2s ease-out;
			height: 0;
			overflow: hidden;
		}

		.VerticalMain {
			height: 100%;
			background-color: #fff;
			flex: 1;
			padding: 25rpx 0rpx 5rpx 10rpx;
		}

		.view-box {
			width: 100%;
			height: 100%;
		}

		.view-box image {
			width: 48rpx;
			height: 48rpx;
		}

		.cu-bar {
			width: 567rpx;
			min-height: 304rpx;
			display: flex;
			align-items: normal;
			border-bottom: 1rpx solid #E4E4E4;
			padding: 15px 5rpx 5rpx 25rpx;
			position: relative;

			&:nth-last-child(1) {
				border-bottom: none;
			}

			.immsb {
				position: absolute;
				left: 15rpx;
				top: 5rpx;
				z-index: 8;
				width: 52rpx;
				height: 58rpx
			}

			.showImgs {
				width: 226rpx;
				height: 226rpx;
				position: relative;
				overflow: hidden;

				.sellOut {
					position: absolute;
					left: 0;
					bottom: 0;
					width: 100%;
					height: 40rpx;
					border-radius: 0px 0px 26rpx 26rpx;
					background: rgba(0, 0, 0, 0.50);
					color: #fff;
					text-align: center;
					line-height: 40rpx;
					letter-spacing: 5rpx;
					color: #FFF;
					font-size: 28rpx;
					font-style: normal;
					font-weight: 400;
				}

				.imms {
					width: 100%;
					height: 100%;
					border-radius: 26rpx;
				}

				.hy {
					position: absolute;
					right: 0;
					bottom: 0rpx;
					z-index: 8;
					width: 36rpx;
					height: 36rpx;
					line-height: 37rpx;
					background-color: #F5A623;
					border-radius: 10rpx 0rpx 20rpx 0rpx;

					.hs_s {
						color: #fff;
						font-size: 24rpx;
						display: block;
						padding-left: 6rpx;
						padding-top: 4rpx;
					}
				}
			}

			.shopinfo {
				width: 292rpx;
				height: 100%;
				position: relative;

				.juanhouStyle {
					.juanhouStylefsizi {
						color: #FC4C40;
						font-family: "Microsoft YaHei UI";
						font-size: 10px;
						font-weight: 400;
						line-height: normal;
						margin-top: 10rpx;
						margin-right: 4rpx;
					}

					.juanhoupic {
						color: #FC4C40;
						font-family: "Microsoft YaHei UI";
						font-size: 36rpx;
						font-style: normal;
						font-weight: 700;
						line-height: normal;
					}

					.couponIssuance {
						width: 96rpx;
						height: 32rpx;
						flex-shrink: 0;
						border-radius: 4px;
						border: 0.5px solid #53A87F;
						background: rgba(83, 168, 127, 0.10);
						margin-left: 10rpx;
						// position: absolute;
						// bottom: 0rpx;
						// left:90rpx;
						color: #53A87F;
						font-size: 20rpx;
						font-weight: 400;
						line-height: 32rpx;
						/* 160% */
						display: flex;
						justify-content: center;
						align-items: center;
					}
				}

				.shopinfo-shopname {
					color: #000;
					font-family: "Microsoft YaHei UI";
					font-size: 32rpx;
					font-style: normal;
					font-weight: 700;
				}

				.showinfo-tag {
					display: flex;
					flex-wrap: wrap;
					margin-top: 15rpx;

					.kcal {
						border-radius: 8rpx;
						border: 0.5rpx solid #53A87F;
						color: #53A87F;
						font-size: 22rpx;
						font-style: normal;
						font-weight: 700;
						padding: 5rpx 10rpx 5rpx 10rpx;
						margin-top: 15rpx;
						margin-right: 10rpx;
						display: flex;
						justify-content: center;
						align-items: center;

					}

					.sweet {
						font-weight: 400;
					}

					.fat {
						font-weight: 400;
					}

					.kcal:nth-child(n+2) {
						// margin-left: 15rpx;
					}
				}

				.shop-hasDishes {
					color: #333;
					font-family: "Microsoft YaHei UI";
					font-size: 24rpx;
					font-style: normal;
					font-weight: 400;
					margin-top: 15rpx;
					margin-bottom: 18rpx;
				}

				.show-price {
					width: 100%;
					height: 60rpx;
					margin-top: 5rpx;
					display: flex;
					justify-content: space-between;
					padding-right: 10rpx;

					.price {
						align-items: normal;
						color: #FC4C40;
						font-family: "Microsoft YaHei UI";
						font-size: 36rpx;
						font-style: normal;
						font-weight: 700;
						position: relative;
						padding-top: 4rpx;

						.totalReduce {
							color: #999;
							font-family: "Microsoft YaHei UI";
							font-size: 20rpx;
							font-style: normal;
							font-weight: 400;
							text-decoration: line-through;
							margin-left: 7rpx;
						}

						.limited {
							color: #999;
							font-family: "Microsoft YaHei UI";
							font-size: 20rpx;
							font-style: normal;
							font-weight: 400;
						}
					}

					.priceBtnAv {
						width: 152rpx;
						height: 52rpx;
						border-radius: 26.4rpx;
						background: #53A87F;
						text-align: center;
						line-height: 52rpx;
						color: #fff;
						margin-top: 4rpx;
					}

					.priceBtnAvs {
						min-width: 112rpx;
						height: 52rpx;
						border-radius: 26.4rpx;
						background: #E7EAE8;
						line-height: 52rpx;
						color: #666;
						margin-top: 4rpx;
						display: flex;
						justify-content: center;
						align-items: center;
					}

					.priceBtnAU {
						min-width: 112rpx;
						height: 52rpx;
						border-radius: 26.4rpx;
						background: #53A87F;
						line-height: 52rpx;
						color: #fff;
						margin-top: 4rpx;
						display: flex;
						justify-content: center;
						align-items: center;
					}

					.prUniss {
						width: 45rpx;
						height: 45rpx;
						border-radius: 50%;
						background-color: #53A87F;
					}

					.prUnis {
						width: 45rpx;
						height: 45rpx;
						border-radius: 50%;
						background-color: #E7EAE8;
					}
				}

				.evaluate {
					width: max-content;
					height: 40rpx;
					border-radius: 10rpx;
					background: rgba(235, 239, 251, 0.50);
					margin-top: 15rpx;
					text-align: center;
					color: #7683AA;
					font-family: "Microsoft YaHei UI";
					font-size: 24rpx;
					font-style: normal;
					font-weight: 400;
					line-height: 36rpx;
					padding: 5rpx 30rpx 5rpx 30rpx;
					margin-bottom: 10rpx;
				}
			}
		}

		.shadowBox {
			width: 5rpx;
			height: calc(100vh - 510rpx);
			background-color: #fff;
			box-shadow: -10rpx -2rpx 10.4rpx 0rpx rgba(0, 0, 0, 0.06);
			z-index: 8;
		}

		.uni-badge {
			width: 40rpx;
			height: 40rpx;
		}

		.sc_item {
			width: 100%;
			text-align: center;
			margin: 0;
			border: none;
			min-height: 90rpx;
			position: relative;
			height: auto;
			// padding: 6rpx 0 6rpx 0;

			.par_item {
				width: 100%;
				height: 100%;
				background-color: #fff;
				display: flex;
				justify-content: center;
				align-items: center;
				position: relative;
			}

			.par_item_item {
				flex: 1;
				// position: relative;

				.menus_tags_box {
					display: flex;
					justify-content: flex-end;

					.menus_tags {
						max-width: calc(100% - 30rpx);
						overflow: hidden;
						height: 28rpx;
						border-radius: 30rpx 28rpx 28rpx 0;
						background: #F00;
						font-size: 16rpx;
						font-weight: 400;
						color: #fff;
						padding: 0 6rpx;
						margin-right: 30rpx;
						line-height: 28rpx;
						text-align: center;
					}
				}

			}

			.cur {
				background-color: #fff;
				color: #648C6A;
				text-align: center;
				font-family: "Microsoft YaHei UI";
				font-size: 28rpx;
				font-style: normal;
				font-weight: 700;
				background-color: #53A87F;
				width: 14rpx;
				height: 120rpx;

			}

			// .cur::after {
			// 			content: "";
			// 			width: 8rpx;
			// 			// height: 105.6rpx;
			// 			height:calc(100% - calc(100% - 105rpx));
			// 			position: absolute;
			// 			background-color: #53A87F;
			// 			top: 0rpx;
			// 			left: 0rpx;
			// 			bottom: 0;
			// 		}
			// .cur::after {
			// 	content: "";
			// 	width: 8rpx;
			// 	// height: 105.6rpx;
			// 	height:calc(100% - calc(100% - 105rpx));
			// 	position: absolute;
			// 	background-color: #53A87F;
			// 	top: 0rpx;
			// 	left: 0rpx;
			// 	bottom: 0;
			// }

			.uncur {
				color: #666;
				text-align: center;
				font-family: "Microsoft YaHei UI";
				font-size: 28rpx;
				font-style: normal;
				font-weight: 400;
				width: 8rpx;
				height: 120rpx;
			}
		}

		.sc_item:nth-child(n+2) {
			margin-top: 10rpx;
		}

		.view-box-chindred {
			color: #666;
			text-align: center;
			font-family: "Microsoft YaHei UI";
			font-size: 25rpx;
			font-style: normal;
			font-weight: 400;
			min-height: 80rpx;
			height: auto;
			margin-top: 10rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.childrenActive {
			color: #648C6A;
			font-family: "Microsoft YaHei UI";
			font-size: 28rpx;
			font-weight: 700;
			letter-spacing: 0.83rpx;
			background: rgba(255, 255, 255, 0.70);
			width: 100%;
			height: 100%;
		}


		.numbx {
			position: absolute;
			right: 0;
			top: 0;
			z-index: 1;
			// margin-top: 4rpx;
			// margin-left: 10rpx;
		}
	}

	.speBtn {
		position: absolute;
		right: 8rpx;
		top: 0;
		z-index: 1;
	}

	.mbtn {
		border-radius: 90rpx !important;
	}

	.vnames {
		position: sticky;
		top: -1rpx;
		left: 0;
		width: 100%;
		height: 50rpx;
		background-color: #fff;
		font-weight: 700;
	}

	.badges {
		width: 30rpx;
		height: 30rpx;
		position: absolute;
		right: 0;
		top: 5rpx;
	}

	.priceCommon {
		position: absolute;
		right: 0;
		top: 0;
		background-color: #fff;
	}

	.left_s {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 5rpx;
	}

	.sales_box {
		width: 100%;
		height: 32rpx;
		display: flex;
		// justify-content: flex-start;
		align-items: center;
		margin-top: 15rpx;

		.sales_box_item {
			min-width: 90rpx;
			height: 100%;
			border-radius: 8rpx;
			background: #FDF6EC;
			color: #B7662F;
			font-size: 20rpx;
			padding: 0rpx 5rpx 0rpx 5rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			&:nth-child(n+2) {
				margin-left: 10rpx;
			}
		}
	}
</style>